<?php
namespace Thrift\Transport;



class TStreamSocket extends TSocket
{

    public function getSocketHandle(&$errno, &$errstr)
    {
        for ($i = 0; $i < $this->tryConnectCount; $i++) {
            $flag = STREAM_CLIENT_CONNECT;
            if ($this->persist_) {
                $flag |= STREAM_CLIENT_PERSISTENT;
            }

            $this->handle_ = @stream_socket_client(
                'tcp://'.$this->host_.':'.$this->port_,
                $errno,
                $errstr,
                $this->sendTimeoutSec_ + ($this->sendTimeoutUsec_ / 1000000),
                $flag
            );

            if ($this->handle_) {
                stream_set_blocking($this->handle_, false);
                return true;
            }
        }
        return false;
    }
}
